Use Windows.pkg
Use DFClient.pkg
Use dfallent.pkg
Use cPatientDataDictionary.dd
Use cDoctorDataDictionary.dd
Use cApptDataDictionary.dd
Use cApptdetlDataDictionary.dd
Use cPaymentsDataDictionary.dd
Use DFEntry.pkg
Use cDbTextEdit.pkg
Use dfTabDlg.pkg
Use dfTable.pkg
Use CostCodeSL.sl
Use dfLine.pkg
Use apptlkup.sl
Use cDbCJGrid.pkg
Use dftimer.pkg

Register_Function GetCostCodeDesc String sCode Returns String
Deferred_View Activate_oApptDetails for ;
Object oApptDetails is a dbView
    Property String psMboxCaption "Appointment Details"
    Set Border_Style to Border_Thick
    Set Size to 335 381
    Set Location to 4 4
    Set Label to "Appointment Details"
    Set Icon to "doctor_plus.ico"
    
    Object oDOCTOR_DD is a cDoctorDataDictionary
        Set Field_Option Field DOCTOR.LAST_NAME DD_DISPLAYONLY to True
        Set Field_Option Field DOCTOR.FIRST_NAME DD_DISPLAYONLY to True
        Set Field_Option Field DOCTOR.DOCTOR# DD_DISPLAYONLY to True
    End_Object

    Object oPATIENT_DD is a cPatientDataDictionary
        Set Field_Option Field PATIENT.LAST_NAME DD_DISPLAYONLY to True
        Set Field_Option Field PATIENT.FIRST_NAME DD_DISPLAYONLY to True
        Set Field_Option Field PATIENT.MIDDLE_INIT DD_DISPLAYONLY to True
        Set Field_Option Field PATIENT.PATIENT# DD_DISPLAYONLY to True
    End_Object

    Object oAPPT_DD is a cApptDataDictionary
        Set DDO_Server to oDOCTOR_DD
        Set DDO_Server to oPATIENT_DD
        
        Set Field_Option Field APPT.APPT# DD_DISPLAYONLY to False
        Set Field_Option Field APPT.APPT# DD_NOPUT to True
        Set Field_Option Field APPT.Date DD_NOPUT to True
        Set Field_Option Field APPT.COST_TOTAL DD_DISPLAYONLY to True
        
        Function Request_Validate Returns Integer
            Boolean bFail bHasRecord
            
            Get HasRecord to bHasRecord
            If (not(bHasRecord)) Begin
                Move True to bFail
                Send Info_Box "Unable to create new appointment in this view. To create a new appointment, go to the Appointment Setup view." (psMboxCaption(Self))
            End
            If (not(bFail)) Forward Get Request_Validate to bFail
            Function_Return bFail
        End_Function
    End_Object

    Object oPAYMENTS_DD is a cPaymentsDataDictionary
        Set Constrain_file to APPT.File_number
        Set DDO_Server to oAPPT_DD
    End_Object

    Object oAPPTDETL_DD is a cApptdetlDataDictionary
        Set Constrain_file to APPT.File_number
        Set DDO_Server to oAPPT_DD
    End_Object

    Set Main_DD to oAPPT_DD
    Set Server to oAPPT_DD

    Object oAppointmentTabDialog is a dbTabDialog
        Set Size to 116 341
        Set Location to 7 20
        Set Rotate_Mode to RM_Rotate
        Set peAnchors to anTopLeftRight

        Object oAppointmentTabPage is a dbTabPage
            Set Label to "A&ppointment"

            Object oAPPT_APPT_ is a dbForm
                Entry_Item APPT.APPT#
                Set Location to 12 19
                Set Size to 13 54
                Set Label to "Appt #"
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
                Set Prompt_Button_Mode to PB_PromptOn
                Set Prompt_Object to oAppt_Lkup
            End_Object

            Object oAPPT_DATE is a dbForm
                Entry_Item APPT.Date
                Set Location to 12 118
                Set Size to 13 66
                Set Label to "Date"
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
            End_Object

            Object oAPPT_COST_TOTAL is a dbForm
                Entry_Item APPT.COST_TOTAL
                Set Location to 12 229
                Set Size to 13 66
                Set Label to "Total Cost"
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
            End_Object

            Object oLineControl1 is a LineControl
                Set Size to 2 293
                Set Location to 29 17
            End_Object

            Object oAPPT_PATIENT_ is a dbForm
                Entry_Item PATIENT.PATIENT#
                Set Location to 44 19
                Set Size to 13 66
                Set Label to "Patient #"
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
            End_Object

            Object oPATIENT_LAST_NAME is a dbForm
                Entry_Item PATIENT.LAST_NAME
                Set Location to 44 90
                Set Size to 13 104
                Set Label to "Last Name"
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
            End_Object

            Object oPATIENT_FIRST_NAME is a dbForm
                Entry_Item PATIENT.FIRST_NAME
                Set Location to 44 199
                Set Size to 13 95
                Set Label to "First Name"
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
            End_Object

            Object oPATIENT_MIDDLE_INIT is a dbForm
                Entry_Item PATIENT.MIDDLE_INIT
                Set Location to 44 303
                Set Size to 13 13
                Set Label to "Middle"
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
            End_Object

            Object oLineControl1 is a LineControl
                Set Size to 2 293
                Set Location to 63 17
            End_Object

            Object oAPPT_DOCTOR_ is a dbForm
                Entry_Item DOCTOR.DOCTOR#
                Set Location to 77 19
                Set Size to 13 66
                Set Label to "Doctor #"
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
            End_Object

            Object oDOCTOR_LAST_NAME is a dbForm
                Entry_Item DOCTOR.LAST_NAME
                Set Location to 77 90
                Set Size to 13 104
                Set Label to "Last Name"
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
            End_Object

            Object oDOCTOR_FIRST_NAME is a dbForm
                Entry_Item DOCTOR.FIRST_NAME
                Set Location to 77 199
                Set Size to 13 95
                Set Label to "First Name"
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
            End_Object
        End_Object

        Object oInstructionsTabPage is a dbTabPage
            Set Label to "&Instructions"

            Object oAPPT_INSTRUCTIONS is a cDbTextEdit
                Entry_Item APPT.INSTRUCTIONS
                Set Location to 6 15
                Set Size to 83 305
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
                Set peAnchors to anAll
            End_Object
        End_Object

        Object oNotesTabPage is a dbTabPage
            Set Label to "N&otes"

            Object oAPPT_NOTES is a cDbTextEdit
                Entry_Item APPT.NOTES
                Set Location to 6 15
                Set Size to 83 305
                Set Label_Col_Offset to 0
                Set Label_Justification_Mode to JMode_Top
                Set peAnchors to anAll
            End_Object
        End_Object
        
        Procedure Switch_To_Appointment
            Send Request_Switch_To_Tab 0 3
        End_Procedure
        
        Procedure Switch_To_Instructions
            Send Request_Switch_To_Tab 1 3
        End_Procedure
        
        Procedure Switch_To_Notes
            Send Request_Switch_To_Tab 2 3
        End_Procedure
    
    End_Object

    Object oApptDetlGrid is a cDbCJGrid
        Set Server to oAPPTDETL_DD
        Set Size to 192 341
        Set Location to 134 20
        Set peAnchors to anAll
        Set Ordering to Index.1

        Object oAPPTDETL_COSTCODE is a cDbCJGridColumn
            Entry_Item APPTDETL.COSTCODE
            Set piWidth to 92
            Set psCaption to "Cost Code"
            Set Prompt_Button_Mode to PB_PromptOn
            Set Prompt_Object to oCostCodeSL
        End_Object
        
        Object oCodeDescription is a cDbCJGridColumn
            Set piWidth to 221
            Set psCaption to "Cost Code Description"
            Procedure OnSetCalculatedValue String ByRef sValue
                Clear COSTCODE
                Move APPTDETL.COSTCODE to COSTCODE.COST_CODE
                Find eq COSTCODE by Index.1
                If (Found) Move COSTCODE.DESC to sValue
            End_Procedure
        End_Object

        Object oAPPTDETL_PRICE is a cDbCJGridColumn
            Entry_Item APPTDETL.PRICE
            Set piWidth to 63
            Set psCaption to "Price"
        End_Object

        Object oAPPTDETL_NOTES is a cDbCJGridColumn
            Entry_Item APPTDETL.NOTES
            Set piWidth to 135
            Set psCaption to "Notes"
        End_Object
    End_Object
    
    //-----------------------------------------------------------------------
    // Create Idle time to handle enabling / disabling of grid
    //-----------------------------------------------------------------------
    Object oIdle is a cIdleHandler
        Procedure OnIdle 
            Delegate Send OnIdle
        End_Procedure // OnIdle
    End_Object // oIdle

    Procedure OnIdle 
        Send EnableObjects
    End_Procedure // OnIdle

    Procedure EnableObjects 
        Boolean bChanged bRec
        Handle hoServer
        Get Server to hoServer
        Get Should_Save of hoServer to bChanged
        Get HasRecord of hoServer to bRec
        Set Enabled_State of oApptDetlGrid to (not(bChanged) and bRec)
    End_Procedure // EnableObjects

    Procedure Activating 
        Forward Send Activating
        Set pbEnabled of oIdle to True
    End_Procedure // Activating

    Procedure Deactivating 
        Set pbEnabled of oIdle to False
        Forward Send Deactivating
    End_Procedure // Deactivating

    // Saves in header should not clear the view
    Set Auto_Clear_Deo_State to False
    
    On_Key Key_Alt+Key_P Send Switch_To_Appointment
    On_Key Key_Alt+Key_I Send Switch_To_Instructions
    On_Key Key_Alt+Key_O Send Switch_To_Notes
    
Cd_End_Object
